package com.itheima.service.impl;

import com.itheima.bean.User;
import com.itheima.mapper.UserMapper;
import com.itheima.service.UserService;
import com.itheima.utils.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

public class UserServiceImpl implements UserService {

    /*
     * 定义登录的方法
     * @param user 封装用于登录的用户名和密码
     * @return 返回查到的用户信息
     */

    public User login(String username,String password) {
        //获取SqlSession对象
        SqlSession sqlSession = MybatisUtil.getSqlSession();
        //获取mapper的代理对象，执行操作
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        sqlSession.commit();

        User login = mapper.login(username, password);
        sqlSession.close();
        return login;
    }
}
